package tutorial;
import java.util.Random;
public class SortingArray {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// creates an object with random method 
    Random randomNumber = new Random();
    int[] anArray = new int[10];
    for(int i=0; i<10; i++){
    	// fills the anArray with random numbers from 0...50
 	   anArray[i]= randomNumber.nextInt(50);
 	  System.out.println("anArray["+i+"]" 
              + anArray[i]);
	}
  
	//sorts anArray numbers ascending
	  for (int j=0;j<=8; j++){
	    for (int i=0;i<9-j; i++){
	    	if (anArray[i]>anArray[i+1]) {
	    		int k = anArray[i];
	    		anArray[i]=anArray[i+1];
	    		anArray[i+1]=k;
		 }
	    }	    
	  }
	  for (int i=0;i<=9; i++)
	  System.out.println("sortedArray["+i+"]" 
              + anArray[i]);
	}
}
